package com.geoboard.service;

import java.util.Date;

import android.util.Log;

import com.geoboard.fragments.MapFrag;
import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
import com.google.android.gms.maps.model.CameraPosition;

public class BrowseCameraListener implements OnCameraChangeListener {
	
	private MapFrag mMapFrag;
	private CameraPosition mOldCameraPosition;
	private String TAG;
	private Date mNextCall;
	
	public BrowseCameraListener (MapFrag mapFrag) {
		mMapFrag = mapFrag;
		mNextCall = new Date();
	}

	@Override
	public void onCameraChange(CameraPosition cp) {
		Date mCurCall = new Date();
		if (mCurCall.after(mNextCall)) {
			mNextCall.setTime(mCurCall.getTime() + 1000);
			Log.d(TAG, "onCameraChange");
			if (mOldCameraPosition == null) {
				mOldCameraPosition = cp;
				mMapFrag.getBoards();
			} else if (Math.floor(cp.zoom) != Math.floor(mOldCameraPosition.zoom)) {
				mOldCameraPosition = cp;
				mMapFrag.getBoards();
			} else if (cp.target != mOldCameraPosition.target) {
				mOldCameraPosition = cp;
				mMapFrag.getBoards();
			}
		}
	}

}
